package com.test.map.HTTP;

import org.json.JSONArray;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class OKHttp {
    public JSONArray jsonArray;
    public String s="";
    public Boolean ok;
    public String post(String url, FormBody body){
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                //...
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if(response.isSuccessful()){

                    s=response.body().string();


                   //ok=response.isSuccessful();
                    //处理UI需要切换到UI线程处理
                }
            }
        });
        return s;
    }


}
